package com.gaotai.wangfei.exam.tag;

import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * 
 * <p>
 * Description: [用于for循环的自定义标签]
 * </p>
 * 
 * @author <a href="mailto: wangfei@gaotai.cn">王飞</a>
 * @version $Revision$
 */
public class CycleTag extends TagSupport
{
	/**
	 * <p>
	 * [字段功能描述]
	 * </p>
	 */
	private static final long serialVersionUID = 1L;

	//需要循环输出的字符串list
	private List<String> valueList;

	//getter and setters
	public List<String> getValueList()
	{
		return valueList;
	}

	public void setValueList(List<String> valueList)
	{
		this.valueList = valueList;
	}

	//重写处理类
	@Override
	public int doStartTag() throws JspException
	{
		try
		{
			JspWriter out = this.pageContext.getOut();
			if(valueList == null)
			{
				out.println("No valueList Found...");
				return SKIP_BODY;
			}
			for (String value : valueList)
			{
				out.println("<span style='color:blue'>" + value + "</span></br>");
			}
		}
		catch (Exception e)
		{
			throw new JspException(e.getMessage());
		}
		return SKIP_BODY;
	}

	@Override
	public int doEndTag() throws JspException
	{
		return EVAL_PAGE;
	}

	@Override
	public void release()
	{
		super.release();
		this.valueList = null;
	}
}
